package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Expert;
import com.zzyl.nursing.service.IExpertService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 文物专家Controller
 *
 * @author success
 * @date 2025-03-04
 */
@Api(tags = "文物专家管理")
@RestController
@RequestMapping("/nursing/expert")
public class ExpertController extends BaseController {
    @Autowired
    private IExpertService expertService;

    /**
     * 查询文物专家列表
     */
    @ApiOperation("查询文物专家列表")
    @PreAuthorize("@ss.hasPermi('nursing:expert:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Expert>> list(@ApiParam("文物专家查询条件") Expert expert) {
        startPage();
        List<Expert> list = expertService.selectExpertList(expert);
        return getDataTable(list);
    }

    /**
     * 导出文物专家列表
     */
    @ApiOperation("导出文物专家列表")
    @PreAuthorize("@ss.hasPermi('nursing:expert:export')")
    @Log(title = "文物专家", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam(value = "文物专家查询条件") HttpServletResponse response, Expert expert) {
        List<Expert> list = expertService.selectExpertList(expert);
        ExcelUtil<Expert> util = new ExcelUtil<Expert>(Expert.class);
        util.exportExcel(response, list, "文物专家数据");
    }

    /**
     * 获取文物专家详细信息
     */
    @ApiOperation("获取文物专家详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:expert:query')")
    @GetMapping(value = "/{id}")
    public R<Expert> getInfo(@ApiParam("文物专家ID") @PathVariable("id") Integer id) {
        return R.ok(expertService.selectExpertById(id));
    }

    /**
     * 新增文物专家
     */
    @ApiOperation("新增文物专家")
    @PreAuthorize("@ss.hasPermi('nursing:expert:add')")
    @Log(title = "文物专家", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam("文物专家信息") @RequestBody Expert expert) {
        return toAjax(expertService.insertExpert(expert));
    }

    /**
     * 修改文物专家
     */
    @ApiOperation("修改文物专家")
    @PreAuthorize("@ss.hasPermi('nursing:expert:edit')")
    @Log(title = "文物专家", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("文物专家信息") @RequestBody Expert expert) {
        return toAjax(expertService.updateExpert(expert));
    }

    /**
     * 删除文物专家
     */
    @ApiOperation("删除文物专家")
    @PreAuthorize("@ss.hasPermi('nursing:expert:remove')")
    @Log(title = "文物专家", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("文物专家ID数组") @PathVariable Integer[] ids) {
        return toAjax(expertService.deleteExpertByIds(ids));
    }
}
